<?php

use kartik\datetime\DateTimePicker;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model common\models\ReportModel */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="report-model-form">

    <?php $form = ActiveForm::begin(['id' => 'form_sign']); ?>


    <?= $form->field($model, 'sign')->radioList([1 => '是', 2 => '否'], ['class' => 'report_sign']) ?>

    <div id="form_content" style="display:  <?= $model->sign ==1 ? 'block' :'none'?> ">


        <?= $form->field($model, 'return_time')->widget(DateTimePicker::classname(), [
            'pluginOptions' => [
                'autoclose' => true,
                'todayHighlight' => true,
                'format' => 'yyyy-mm-dd',
                'minView' => 2,
            ],
        ]) ?>

        <?= $form->field($model, 'return_amount')->textInput(['maxlength' => true,'placeholder' =>'万元']) ?>

        <?= $form->field($model, 'sign_time')->widget(DateTimePicker::classname(), [
            'pluginOptions' => [
                'autoclose' => true,
                'todayHighlight' => true,
                'format' => 'yyyy-mm-dd',
                'minView' => 2,
            ],
        ]) ?>

        <?= $form->field($model, 'sign_amount')->textInput(['maxlength' => true,'placeholder' =>'万元']) ?>

        <?= $form->field($model, 'sign_house')->textInput() ?>
    </div>
    <div class="form-group">
        <?= Html::button('保存', ['class' => 'btn btn-success save']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<?php $this->beginBlock('footer') ?>
<script>
    $(function () {
        $('input[type=radio]', '.field-reportmodel-sign').click(function () {
            if($(this).val() == '1'){
              $('#form_content').show();
            }else{
                $('#form_content').hide();
            }
        });
        $('.save').click(function () {
            var val = $('input[type=radio]:checked', '.field-reportmodel-sign').val();
            if (val == undefined) {
                alert('请选择是否签约');
            } else {
                if (val == 1) {
                    if ($('#reportmodel-return_time').val() == '') {
                        alert('请输入返现时间');
                        return;
                    }
                    if ($('#reportmodel-return_amount').val() == '') {
                        alert('请输入返现金额');
                        return;
                    }
                    if ($('#reportmodel-sign_time').val() == '') {
                        alert('请输入签约时间');
                        return;
                    }
                    if ($('#reportmodel-sign_amount').val() == '') {
                        alert('请输入签约金额');
                        return;
                    }
                    if ($('#reportmodel-sign_house').val() == '') {
                        alert('请输入签约户型');
                        return;
                    }
                }
                if (confirm('提交签约信息后不能修改，确定提交吗？')) {

                    $('#form_sign').submit();
                }
            }
        });
    });
</script>
<?php $this->endBlock() ?>
